package com.da.javatest.leetCode2;

public class Code35 {
    public int searchInsert(int[] nums, int target) {
        if (target <= nums[0]) {
            return 0;
        }
        if (target > nums[nums.length - 1]) {
            return nums.length;
        }
        for (int i = 0; i < nums.length; i++) {
            if (target == nums[i]) {
                return i;
            }
            if (target > nums[i - 1] && target < nums[i]) {
                return i;
            }
        }
        return -1;
    }
}
